<%@ page language="java" import="com.demo.util.Conn,java.sql.ResultSet" pageEncoding="UTF-8"%>
<%
String success = "index_com.jsp";
if (session.getAttribute("user_id") != null) {
	response.sendRedirect(success);
}
String errMsg = "";
String login = "";
String pwd = "";

if ("POST".equals(request.getMethod())) {
	login = request.getParameter("login");
	pwd = request.getParameter("pwd");
	
	StringBuffer sql = new StringBuffer();
	sql.append("select * from DBF_ADMIN_USER where login='" + login + "'");
	sql.append(" and password='" + pwd + "'");
	ResultSet rs = new Conn().find(sql.toString());
	if (null != rs && rs.next()) {
		session.setAttribute("admin_user_id", rs.getString("admin_user_id"));
		response.sendRedirect(success);
		rs.close();
	} else {
		errMsg = "incorrect Login or Password!";
	}
	
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Login</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
  	<link rel="stylesheet" type="text/css" href="../style.css">
  </head>
  
  <body>
  	<form action="login.jsp" method="post">
	  	<table width="375" border="0" align="center" cellpadding="5" cellspacing="0">
          <tr>
            <td height="319" background="../images/login_all.jpg"><table width="80%" border="0" align="center" cellpadding="0" cellspacing="0" class="logintxt">

              <tr>
                <td colspan="2">Login:&nbsp;</td>
                <td colspan="2" align="left"><input name="login" type="text" class="logintxt" style="width:150px;" value="<%=login %>"/></td>
              </tr>
              <tr>
                <td colspan="2">Password:&nbsp;</td>
                <td colspan="2" align="left"><input name="pwd" type="password" class="logintxt" style="width:150px;" value="<%=pwd %>"/></td>
              </tr>
              <tr class="errMsg">
                <td height="15" colspan="4" style="color:red;text-align:center">&nbsp;<%=errMsg %></td>
              </tr>
              <tr>
                <td width="30%">&nbsp;</td>
                <td width="20%" align="right">&nbsp;</td>
                <td width="20%" align="left"><input name="submit" type="image" src="../images/login_btn.jpg" value="submit" /></td>
                <td width="30%">&nbsp;</td>
              </tr>
            </table></td>
          </tr>
        </table>
  </form>
  </body>
</html>
